package org.activiti.explorer.servlet.rest;

import org.activiti.rest.common.application.ContentTypeResolver;
import org.activiti.rest.common.application.DefaultContentTypeResolver;
import org.activiti.rest.service.api.RestResponseFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

//@Configuration
//@ComponentScan({
//    "org.activiti.rest.service.api",
//    })
//@EnableAsync
public class RestServletConfiguration extends WebMvcConfigurationSupport {

  private final Logger log = LoggerFactory.getLogger(RestServletConfiguration.class);

  //@Bean
  public RestResponseFactory restResponseFactory() {
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    return restResponseFactory;
  }

  //@Bean
  public ContentTypeResolver contentTypeResolver() {
    ContentTypeResolver resolver = new DefaultContentTypeResolver();
    return resolver;
  }

//@Bean
//public MultipartResolver multipartResolver() {
//  PutAwareCommonsMultipartResolver multipartResolver = new PutAwareCommonsMultipartResolver();
//  return multipartResolver;
//}

//  @Bean
//  public SessionLocaleResolver localeResolver() {
//    return new SessionLocaleResolver();
//  }

//  @Bean
//  public LocaleChangeInterceptor localeChangeInterceptor() {
//    log.debug("Configuring localeChangeInterceptor");
//    LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
//    localeChangeInterceptor.setParamName("language");
//    return localeChangeInterceptor;
//  }

//  @Bean
//  public RequestMappingHandlerMapping requestMappingHandlerMapping() {
//    log.debug("Creating requestMappingHandlerMapping");
//    RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
//    requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
//    Object[] interceptors = {localeChangeInterceptor()};
//    requestMappingHandlerMapping.setInterceptors(interceptors);
//    return requestMappingHandlerMapping;
//  }

//  @Bean
//  public FilterRegistrationBean filterRegistration(DispatcherServlet dispatcherServlet){
//      FilterRegistrationBean bean = new FilterRegistrationBean();
//      bean.setFilter(new ExplorerFilter());
//      bean.addUrlPatterns("/activiti-explorer/*");
//      bean.addServletRegistrationBeans(new ServletRegistrationBean(dispatcherServlet));
//      return bean;
//  }
  
//  @Bean
//  public ServletListenerRegistrationBean<EventListener> listenerRegistration(){
//      ServletListenerRegistrationBean<EventListener> bean = new ServletListenerRegistrationBean<>();
//      bean.setListener(new RequestContextListener());
//      return bean; 
//  }

  //@Bean(name="RestServlet")
  public ServletRegistrationBean restServlet(DispatcherServlet dispatcherServlet){
      ServletRegistrationBean bean = new ServletRegistrationBean(dispatcherServlet);
      bean.setName("RestServlet");
      //bean.setServlet(new DispatcherServlet());
      bean.addUrlMappings("/rest/*");
      return bean;
  }

//  @Override
//  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//    addDefaultHttpMessageConverters(converters);
//    for (HttpMessageConverter<?> converter: converters) {
//      if (converter instanceof MappingJackson2HttpMessageConverter) {
//        MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) converter;
//        jackson2HttpMessageConverter.setObjectMapper(objectMapper);
//        break;
//      }
//    }
//  }

//  @Override
//  protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
//    configurer.favorPathExtension(false);
//  }
  
}
